package com.ndhutu.ee.util.netease.signal;

import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.ndhutu.ee.util.http.OKHttpUtil;
import com.ndhutu.ee.util.netease.App;
import com.ndhutu.ee.util.netease.NeteaseUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * 云信信令工具类
 * Author Shane
 * @Date 2020/6/4 14:48
 */
public class SignalUtil {
    
    /**
     * 信令控制指令
     * @Author Shane
     * @Date 2020/6/4 15:08
     * @param channelId 房间id
     * @param from      发送者
     * @param to        接收者
     * @param attachExt 扩展字段
     * @return 
     */
    public static void ctrlRoom(String channelId, String from, String to, Map<String, Object> attachExt, App app) throws Exception{
        String url = "https://api.netease.im/nimserver/signal/ctrlRoom.action";
        Map<String, String> headers = NeteaseUtil.getRequestHeaders(app);

        Map<String, Object> params = new HashMap<>();
        params.put("channelId", channelId);
        params.put("from", from);
        params.put("to", to);
        params.put("attachExt", JSONObject.toJSONString(attachExt));

        Map<String, Object> map = NeteaseUtil.post(url, params, headers);
        System.out.println(JSONObject.toJSONString(map));
        if(Integer.parseInt(map.get("code")+"") != 200){
            throw new Exception("信令控制指令执行失败");
        }
    }
}
